package com.myidis.mapper;

import java.util.ArrayList;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.myidis.entity.Department;

public interface DeptMapper {
	@Select("SELECT * FROM department ORDER BY parent")
    @Results({
        @Result(property = "parent",  column = "parent"),
        @Result(property = "name", column = "name")
    })
    ArrayList<Department> all();
	
	@Select("SELECT * FROM department WHERE parent = #{parent}")
    @Results({
    	@Result(property = "parent",  column = "parent"),
        @Result(property = "name", column = "name")
    })
	ArrayList<Department> getByParent(int parent);

    @Select("SELECT * FROM department WHERE id = #{id}")
    @Results({
    	@Result(property = "parent",  column = "parent"),
        @Result(property = "name", column = "name")
    })
    Department getOne(int id);

    @Insert("INSERT INTO department(parent, name) VALUES(#{parent}, #{name})")
    int insert(Department dept);

    @Update("UPDATE department SET parent = #{parent}, name = #{name} WHERE id = #{id}")
    int update(Department dept);

    @Delete("DELETE FROM department WHERE id = #{id}")
    int delete(int id);
}
